﻿/*----------------------------------------------------------------
    // Copyright (C) 2009 江苏华招网
    // 版权所有。 
    // 作者：吕海乐 
    //
    // 文件名：HospitalCheckeList.aspx.cs
    // 文件功能描述：审核医疗机构
    // 创建标识：吕海乐2009-05-31
    //
    // 修改标识：
    // 修改描述：
    //
    // 修改标识：
    // 修改描述：
    //
    // 审核人：
// 审核时间：
// 审核说明：
 //----------------------------------------------------------------*/
using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HZ.DrugTrade.Model;
using HZ.DrugTrade.IBLL;
using HZ.DrugTrade.BLLFactory;
using HZ.DrugTrade.Model.Enum;
namespace HZ.DrugTrade.Web.Admin.SystemManage
{
    public partial class HospitalCheckeList : BasePage
    {
        public HospitalCheckeList()
        {
            this.ModuleNo = Module.系统管理.ToString();
            this.PageOperateType = OperateType.医疗机构管理.ToString();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                Banding();
                //若无需审核的医疗机构信息，将审核按钮和删除按钮屏蔽
                if (gvwChildUserList.Rows.Count <= 0)
                {
                    btnBatResetPws.Visible = false;
                    btnBatUnLock.Visible = false;
                }
            }
        }

        IBLL_Hospital ih = Factory.BLL_Hospital();

        private void Banding()
        {
            //从页面获取分页大小
            int iPageSize = Convert.ToInt32(this.dplPageSize.SelectedValue);
            int totalCount;
            AspNetPager1.PageSize = iPageSize;
            Model.Query.HospitalInfo qHospitalInfo = new HZ.DrugTrade.Model.Query.HospitalInfo();
            qHospitalInfo.HospitalName = txtHospitalname.Text.Trim();
            IList<Model.HospitalInfo> lstHospitalInfo = ih.GetUnregedHopialInfo(qHospitalInfo, AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out totalCount);
            this.AspNetPager1.RecordCount = totalCount;
            gvwChildUserList.PageSize = AspNetPager1.PageSize;
            gvwChildUserList.DataSource = lstHospitalInfo;
            gvwChildUserList.DataBind();
        }

        /// <summary>
        /// 翻页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void AspNetPager1_OnPageChanged(object sender, EventArgs e)
        {
            Banding();
        }

        /// <summary>
        /// 审核通过
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnBatUnLock_Click(object sender, EventArgs e)
        {
            IList<Model.HospitalInfo> lstHospitalInfo = new List<Model.HospitalInfo>();
            if (gvwChildUserList.Rows.Count <= 0)
            {
                return;
            }

            for (int i = 0; i < gvwChildUserList.Rows.Count; i++)
            {
                System.Web.UI.HtmlControls.HtmlInputCheckBox chk = (System.Web.UI.HtmlControls.HtmlInputCheckBox)gvwChildUserList.Rows[i].FindControl("chkChildUser");
                Label lblContactPerson = gvwChildUserList.Rows[i].FindControl("lblContactPerson") as Label;
                Label lblAdress = gvwChildUserList.Rows[i].FindControl("lblAddress") as Label;
                Label lblTel = gvwChildUserList.Rows[i].FindControl("lblTelNo") as Label;
                if (chk.Checked == true)
                {
                    Model.HospitalInfo aHospitalInfo = new HZ.DrugTrade.Model.HospitalInfo();
                    aHospitalInfo.AreaID = gvwChildUserList.DataKeys[i].Value.ToString();
                    aHospitalInfo.HospitalName = chk.Value;
                    aHospitalInfo.ContactPerson = lblContactPerson.Text;
                    aHospitalInfo.Address = lblAdress.Text;
                    aHospitalInfo.TelNo = lblTel.Text;
                    lstHospitalInfo.Add(aHospitalInfo);
                }
            }

            int flag = ih.AuditHospital(lstHospitalInfo);
            if (flag == 1)
            {
                HZ.Web.WebUtil.Alert("批量审核执行成功！", this);
                //刷新绑定
                Banding();
            }
            else
            {
                PageError("审核失败！", "HospitalCheckeList.aspx");
            }
        }

        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnQuery_Click(object sender, EventArgs e)
        {
            AspNetPager1.CurrentPageIndex = 1;
            Banding();
        }

        /// <summary>
        /// 删除不需要的医疗机构
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnBatResetPws_Click(object sender, EventArgs e)
        {
            IList<Model.HospitalInfo> lstHospitalInfo = new List<Model.HospitalInfo>();

            if (gvwChildUserList.Rows.Count <= 0)
            {
                return;
            }

            for (int i = 0; i < gvwChildUserList.Rows.Count; i++)
            {
                System.Web.UI.HtmlControls.HtmlInputCheckBox chk = (System.Web.UI.HtmlControls.HtmlInputCheckBox)gvwChildUserList.Rows[i].FindControl("chkChildUser");
                if (chk.Checked == true)
                {
                    Model.HospitalInfo aHospitalInfo = new HZ.DrugTrade.Model.HospitalInfo();
                    aHospitalInfo.HospitalName = chk.Value;
                    lstHospitalInfo.Add(aHospitalInfo);
                }
            }

            int flag = ih.DeleteHospitalInfo(lstHospitalInfo);
            if (flag == 1)
            {
                PageInfo("删除成功！", "HospitalCheckeList.aspx");
            }
            else
            {
                PageError("删除失败！", "HospitalCheckeList.aspx");
            }
        }
    }
}
